<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <!-- el-row是行组件 -->
        <!-- el-col是列 默认一行24份 可以利用span指定col所占的份数 -->
        <!-- 用了一个行列布局 -->
        <tree-tools :is-root="true" :tree-node="company" @openDialog="openDialog" />
        <el-tree :data="departs" default-expand-all :expand-on-click-node="false">
          <!-- el-tree组件在封装的时候支持作用域插槽
          其中的data和node是由组件的开发者决定的 -->
          <tree-tools slot-scope="{ data }" :tree-node="data" @openDialog="openDialog" @delDep="getDepartments" />
        </el-tree>
      </el-card>
    </div>
    <!-- 新增的弹窗组件 -->
    <add-dept :show-dialog.sync="showAddDialog" />
  </div>
</template>

<script>
import TreeTools from './components/tree-tools.vue'
import AddDept from './components/add-dept.vue'
import { getDepartments } from '@/api/departments.js'
import { tranListToTreeData } from '@/utils'
export default {
  components: {
    TreeTools,
    AddDept
  },
  data() {
    return {
      showAddDialog: false,
      treeNode: {},
      departs: [
      ],
      company: { name: '江苏传智播客教育科技股份有限公司', manager: '负责人' }
      // defaultProps: {
      //   label: 'name', // 表示 从这个属性显示内容
      //   children: 'children'
      // }
    }
  },
  created() {
    this.getDepartments()
  },
  methods: {
    async getDepartments() {
      const result = await getDepartments()
      this.departs = tranListToTreeData(result.depts, '')
    },
    openDialog() {
      // this.treeNode = treeNode
      this.showAddDialog = true
    }
  }
}
</script>

<style>
</style>
